/**
 * 全局变量
 */
var pageNoOne;
var pageSizeOne;
var countOne;
var id = ""; // 入库单ID






/**
 * 弹出查看框
 */
function ejectSee(){
	 $.jBox($("#divSeeInStorage").html(), {
		id: 'seeInStorageJBox', 
		title : "添加产品",
		width : 'auto',
		height : 'auto',
		buttons : {"关闭" : true },
		submit : function(v, h, f) {
	  		if (v == false) {
	  			return true;
	  		}
	  	}
	});
}

/**
 * 查看入库单
 */
function see(obj){
	id = $(obj).next().val();
	$("#codeNums").attr('value',$(obj).parent().parent().children("td:eq(1)").html());
	$("#inStorageTypeName").attr('value',$(obj).parent().parent().children("td:eq(2)").html());
	$("#supplierName").attr('value',$(obj).parent().parent().children("td:eq(3)").html());
	$("#orderNumbers").attr('value',$(obj).parent().parent().children("td:eq(4)").html());
	$("#docMaker").attr('value',$(obj).parent().parent().children("td:eq(8)").html());
	$("#productInfoTbody").html("");
	var newRow = '';
	//获取列信息
	$.getJSON("/jeesite/a/en/inStorageDetail/seeInStorage", "inStorage.id=" + id, function(data) {
		if(typeof(data.list) != "undefined" && data.list.length >= 1){
			$.each(data.list, function(i, info) { 
				newRow += '<tr>';
				if(typeof(info.productInfo) != "undefined"){
					newRow += '<td>'+info.productInfo.name+'</td>'
						+'<td>'+info.productInfo.productCode+'</td>'
						+'<td>'+info.productInfo.specifications+'</td>'
						+'<td>'+info.productInfo.brand+'</td>'
						+'<td>'+info.productInfo.packaging+'</td>';
				}else{
					newRow += '<td></td>'
						+'<td></td>'
						+'<td></td>'
						+'<td></td>'
						+'<td></td>';
				}
				newRow += '<td>'+info.batch+'</td>'
					+'<td>'+info.price+'</td>'
					+'<td>'+info.count+'</td>'
					+'<td>'+info.count * info.price+'</td>';
					if(typeof(info.storageLocal) != "undefined"){
						newRow += '<td>'+info.storageLocal.name+'</td>';
					}else{
						newRow += '<td></td>';
					}
				newRow += '</tr>';
			});
			$("#productInfoTbody").append(newRow);
		}
		pageNoOne = data.pageNo;
		pageSizeOne = data.pageSize;
		countOne = data.count;
		$("#clientelePageNo").html(pageNoOne);
		$("#clientelePageSize").html(pageSizeOne);
		$("#clienteleCount").html(countOne);
		if(pageNoOne <= 1){
			$("#clientelePreviousPageLi").attr("class","disabled");
		}
		if(pageNoOne >= countOne/pageSizeOne){
			$("#clienteleNextPageLi").attr("class","disabled");
		}
		//弹出选择框
		ejectSee();
	});
}

/**
 * 下一页
 */
$("#clienteleNextPage").live("click",function(){
	if(pageNoOne < countOne/pageSizeOne){
		$("#productInfoTbody").html("");
		var page;
		var realDetailList;
		var newRow = '';
		//获取列信息
		$.getJSON("/jeesite/a/en/inStorageDetail/seeInStorage", "pageNo="+(pageNoOne+1)+"&inStorage.id=" + id, function(data) {
			if(typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i, info) { 
					newRow += '<tr>';
					if(typeof(info.productInfo) != "undefined"){
						newRow += '<td>'+info.productInfo.name+'</td>'
							+'<td>'+info.productInfo.productCode+'</td>'
							+'<td>'+info.productInfo.specifications+'</td>'
							+'<td>'+info.productInfo.brand+'</td>'
							+'<td>'+info.productInfo.packaging+'</td>';
					}else{
						newRow += '<td></td>'
							+'<td></td>'
							+'<td></td>'
							+'<td></td>'
							+'<td></td>';
					}
					newRow += '<td>'+info.batch+'</td>'
						+'<td>'+info.price+'</td>'
						+'<td>'+info.count+'</td>'
						+'<td>'+info.count * info.price+'</td>';
						if(typeof(info.storageLocal) != "undefined"){
							newRow += '<td>'+info.storageLocal.name+'</td>';
						}else{
							newRow += '<td></td>';
						}
					newRow += '</tr>';
				});
				$("#productInfoTbody").append(newRow);
			}
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#clientelePageNo").html(pageNoOne);
			$("#clientelePageSize").html(pageSizeOne);
			$("#clienteleCount").html(countOne);
			$("#clientelePreviousPageLi").attr("class","");
			if(pageNoOne <= 1){
				$("#clientelePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#clienteleNextPageLi").attr("class","disabled");
			}
			$.jBox.close(selectJBox);
			//弹出选择框
			ejectSee();
		});
	}
});

/**
* 上一页
*/
$("#clientelePreviousPage").live("click",function(){
	if(pageNoOne > 1){
		$("#productInfoTbody").html("");
		var page;
		var realDetailList;
		var newRow = '';
		//获取列信息
		$.getJSON("/jeesite/a/en/inStorageDetail/seeInStorage", "pageNo="+(pageNoOne-1)+"&inStorage.id=" + id, function(data) {
			if(typeof(data.list) != "undefined" && data.list.length >= 1){
				$.each(data.list, function(i, info) { 
					newRow += '<tr>';
					if(typeof(info.productInfo) != "undefined"){
						newRow += '<td>'+info.productInfo.name+'</td>'
							+'<td>'+info.productInfo.productCode+'</td>'
							+'<td>'+info.productInfo.specifications+'</td>'
							+'<td>'+info.productInfo.brand+'</td>'
							+'<td>'+info.productInfo.packaging+'</td>';
					}else{
						newRow += '<td></td>'
							+'<td></td>'
							+'<td></td>'
							+'<td></td>'
							+'<td></td>';
					}
					newRow += '<td>'+info.batch+'</td>'
						+'<td>'+info.price+'</td>'
						+'<td>'+info.count+'</td>'
						+'<td>'+info.count * info.price+'</td>';
						if(typeof(info.storageLocal) != "undefined"){
							newRow += '<td>'+info.storageLocal.name+'</td>';
						}else{
							newRow += '<td></td>';
						}
					newRow += '</tr>';
				});
				$("#productInfoTbody").append(newRow);
			}
			pageNoOne = data.pageNo;
			pageSizeOne = data.pageSize;
			countOne = data.count;
			$("#clientelePageNo").html(pageNoOne);
			$("#clientelePageSize").html(pageSizeOne);
			$("#clienteleCount").html(countOne);
			$("#clienteleNextPageLi").attr("class","");
			if(pageNoOne <= 1){
				$("#clientelePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#clienteleNextPageLi").attr("class","disabled");
			}
			$.jBox.close(selectJBox);
			//弹出选择框
			ejectSee();
		});
	}
});


/**
 * 批量删除数据
 */
function deleteData() {
	var $id = $("input[name='id']:checked");
	var ids = new Array();
	var j = 0;
	if ($id.val() != null && $id.val() != '') {
		var submit = function(v, h, f) {
			if (v == 'ok') {
				$id.each(function(i, info) {
					ids[j] = info.value;
					j++;
				});
				resetTip();
				location.href = "/jeesite/a/en/inStorageDetail/deleteData?ids=" + ids;
			} else if (v == 'cancel') {
				return true;
			}
		};
		$.jBox.confirm("确认删除此信息吗？", "提示", submit);
	} else {
		jBox.tip("请勾选需要删除的数据！");
	}
}

/**
 * 分页
 * 
 * @param n
 * @param s
 * @returns {Boolean}
 */
function page(n, s) {
	$("#pageNo").val(n);
	$("#pageSize").val(s);
	$("#searchForm").attr("action", "/jeesite/a/en/inStorageDetail/list");
	$("#searchForm").submit();
	return false;
}

/**
 * 审核
 * @param flag 标识 0：所有，1：带审核，2：审核通过，3：审核失败
 */
function examine(flag){
	if(flag == 0){
		
	}else if(flag == 1){
		
	}else if(flag == 2){
		
	}else if(flag == 3){
		
	}
}

/**
 * 高级搜索
 */
$("#seniorSearch").live('click',function(){ 
	$("#seniorSearchDiv").toggle(500);
}); 

/**
 * 全选
 */
$("#checkAll").live('click',function() {
	$('input[name="id"]').attr("checked", this.checked);
});

$("#btnExport").live('click',function() {
	top.$.jBox.confirm("确认要导出产品数据吗？", "系统提示", function(v, h, f) {
		if (v == "ok") {
			$("#searchForm").attr("action", "/jeesite/a/en/inStorageDetail/export");
			$("#searchForm").submit();
		}
	}, {
		buttonsFocus : 1
	});
	top.$('.jbox-body .jbox-icon').css('top', '55px');
});
